package com.cml.dm.admin.service.impl;

import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.cml.dm.admin.service.EncryptionFactory;
import org.springframework.stereotype.Component;

@Component
public class SM4Encryption implements EncryptionFactory {

    public static SymmetricCrypto sm4 = new SymmetricCrypto("SM4/ECB/PKCS5Padding", key.getBytes());
    @Override
    public byte[] encode(byte[] bytes) {
        return sm4.encrypt(bytes);
    }

    @Override
    public byte[] decode(byte[] bytes) {
        return sm4.decrypt(bytes);
    }

    @Override
    public String encode(String str) {
        return sm4.encryptBase64(str);
    }

    @Override
    public String decode(String str) {
        return sm4.decryptStr(str);
    }
}
